package comment.action;

import blogData.service.BlogDataService;
import com.opensymphony.xwork2.ActionSupport;
import comment.entity.CommentVO;
import comment.service.CommentService;
import generic.page.Pages;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import util.ObtainOther;

/**
 * Created by chensui on 2017/1/1.
 */
public class CommentAction extends ActionSupport {

    private final static Log LOGER = LogFactory.getLog(CommentAction.class);

    private Integer blogDataId;

    private BlogDataService blogDataService;

    private String message;

    private CommentService commentService;

    private Integer commentId;
    
    private CommentVO commentVO;
    
    private Pages pages;

    private Integer articleId;

    public Integer getArticleId() {
        return articleId;
    }

    public void setArticleId(Integer articleId) {
        this.articleId = articleId;
    }

    public Pages getPages() {
        return pages;
    }

    public void setPages(Pages pages) {
        this.pages = pages;
    }

    public CommentVO getCommentVO() {
        return commentVO;
    }

    public void setCommentVO(CommentVO commentVO) {
        this.commentVO = commentVO;
    }

    public Integer getCommentId() {
        return commentId;
    }

    public void setCommentId(Integer commentId) {
        this.commentId = commentId;
    }

    public CommentService getCommentService() {
        return commentService;
    }

    public void setCommentService(CommentService commentService) {
        this.commentService = commentService;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public BlogDataService getBlogDataService() {
        return blogDataService;
    }

    public void setBlogDataService(BlogDataService blogDataService) {
        this.blogDataService = blogDataService;
    }

    public Integer getBlogDataId() {
        return blogDataId;
    }

    public void setBlogDataId(Integer blogDataId) {
        this.blogDataId = blogDataId;
    }

    /**
     * 删除评论
     *
     * @return
     */
    public String deleteComment() {
        try {
            commentService.deleteCommentById(commentId);
            message = ObtainOther.obtainMessage("deleteCommentSuccess");
            return SUCCESS;
        } catch (Exception e) {
            message = ObtainOther.obtainMessage("deleteCommentError");
            LOGER.error(message + ":/n" + e);
            return ERROR;
        }
    }

    
    /**
     * 分页显示评论
     *
     * @return
     */
    public String listCommentByBlogData() {
        try {
            blogDataId = ObtainOther.obtainId();
            pages = commentService.queryPageByBlogData(pages, blogDataId);
            return SUCCESS;
        } catch (Exception e) {
            message = ObtainOther.obtainMessage("listCommentError");
            LOGER.error(message + ":/n" + e);
            return ERROR;
        }
    }

    /**
     * 分页显示评论
     *
     * @return
     */
    public String listCommentByArticle() {
        try {
            pages = commentService.queryPageByArticle(pages, articleId);
            return SUCCESS;
        } catch (Exception e) {
            message = ObtainOther.obtainMessage("listCommentError");
            LOGER.error(message + ":/n" + e);
            return ERROR;
        }
    }

    /**
     * 读取评论
     *
     * @return
     */
    public String loadComment() {
        try {
            commentVO = commentService.findCommentVOById(commentId);
            return SUCCESS;
        } catch (Exception e) {
            message = ObtainOther.obtainMessage("loadCommentError");
            LOGER.error(message + ":/n" + e);
            return ERROR;
        }
    }


}
